package com.jerry.template.module.mianpage.shouye.recommend.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jerry.template.R;
import com.jerry.template.module.mianpage.shouye.recommend.home.entity.TouGaoEntity;
import com.jerry.template.views.CircleImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by Administrator on 16-5-14.
 */
public class MyUserDetailAdapter<T> extends BaseAdapter {
    private Context context;
    private List<T> objects;
    private LayoutInflater layoutInflater;

    public MyUserDetailAdapter(Context context, List<T> objects) {
        this.context = context;
        this.objects = objects;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return objects == null ? 0 : objects.size();
    }

    @Override
    public T getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.user_down_list_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) (convertView.getTag());
        }
        T obj = getItem(position);
        if (obj instanceof TouGaoEntity.DataBean.DataBean1 && obj != null && viewHolder != null) {
            TouGaoEntity.DataBean.DataBean1 entity = (TouGaoEntity.DataBean.DataBean1) obj;

            Glide.with(context).load(entity.getGroup().getUser().getAvatar_url()).into(viewHolder.user_head);

            viewHolder.title.setText(entity.getGroup().getUser().getName() + "");

            viewHolder.content.setText(entity.getGroup().getText());

            viewHolder.tag.setText(entity.getGroup().getCategory_name());

            if (entity.getGroup().getLarge_cover() == null) {
                viewHolder.content_imgOrGifOrVideo.setImageDrawable(context.getResources().getDrawable(R.drawable.icon));
            } else {

                Glide.
                        with(context).
                        load(entity.getGroup().getLarge_cover().getUrl_list().get(0).getUrl()).
                        into(viewHolder.content_imgOrGifOrVideo);
            }

            viewHolder.zanYiGe.setText(entity.getGroup().getDigg_count() + "");
            viewHolder.unUseless.setText(entity.getGroup().getBury_count() + "");
            viewHolder.commentNum.setText(entity.getGroup().getComment_count() + "");
            viewHolder.shareNum.setText(entity.getGroup().getShare_count() + "");
            viewHolder.position = position;
        }
        return convertView;
    }

    class ViewHolder {

        public CircleImageView user_head;


        public TextView title;


        public TextView content;


        public Button tag;

        public ImageView content_imgOrGifOrVideo;


        public Button zanYiGe;


        public Button unUseless;


        public Button commentNum;


        public Button shareNum;

        public int position;

        public ViewHolder(View view) {
            user_head = (CircleImageView) view.findViewById(R.id.user_head);
            title = (TextView) view.findViewById(R.id.title);
            content = (TextView) view.findViewById(R.id.content);
            tag = (Button) view.findViewById(R.id.tag);
            content_imgOrGifOrVideo = (ImageView) view.findViewById(R.id.content_imgOrGifOrVideo);
            zanYiGe = (Button) view.findViewById(R.id.zanYiGe);
            unUseless = (Button) view.findViewById(R.id.unUseless);
            commentNum = (Button) view.findViewById(R.id.commentNum);
            shareNum = (Button) view.findViewById(R.id.shareNum);
        }
    }
}
